package com.edgardeng;

import com.edgardeng.generator.GeneratorApplication;
import com.edgardeng.generator.entity.FileTree;
import com.edgardeng.utils.JsonUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.io.IOException;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {GeneratorApplication.class})// 指定启动类
@EnableAutoConfiguration
public class GeneratorTestApplication {

    @Test
    public void contextLoads() {
        System.out.println(" --- GeneratorTestApplication.contextLoads");
    }

    public static void main(String[] args) {
        // 读取项目路径下的文件 json/person.json
        FileTree tree = new FileTree();
        List<FileTree> trees = null;
        try {
            trees = JsonUtils.readJsonListFromClassPath("json/jupiter-system-ui.json", FileTree.class);
//            System.out.println(person.toString());
            tree.setPath("/Users/edgar/workspace/jupiter-code-generator");
            tree.setList(trees);
            tree.setDir(true);
            check(tree);
            // 遍历 FileTree
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public static void check(FileTree tree) {
        if (tree.getList() == null) {
            System.out.println("error:" + tree.getName());
            return;
        }
        for (FileTree list : tree.getList()) {
            list.setPath(tree.getPath() + File.separator + list.getName());
            System.out.println(list.getName());
            System.out.println(list.getPath());
            if (list.isDir()) {
                check(list);
            }
        }
    }


}
